﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class control_BidHistory : System.Web.UI.UserControl
{
    #region 辅助数据结构
    //评论对方的三种状态
    public enum CommentState
    {
        /// <summary>
        /// 评论前
        /// </summary>
        noComment,
        /// <summary>
        /// 评论前
        /// </summary>
        beforeComment,
        /// <summary>
        /// 评论后对方未回复
        /// </summary>
        afterCommentBeforReplied,
        /// <summary>
        /// 对方回复后
        /// </summary>
        afterReplied
    }
    //被评论的三种状态
    public enum CommentedState
    {
        /// <summary>
        /// 被评论前
        /// </summary>
        beforeCommented,
        /// <summary>
        /// 被评论后被评论者未回复
        /// </summary>
        afterCommentedBeforeReply,
        /// <summary>
        /// 被评论者回复后
        /// </summary>
        afterReply
    }
    #endregion

    //构造函数
    protected void Page_Load(object sender, EventArgs e)
    {
        this.commentForm.button1ClickEvent += new control_Reply.Button1ClickHandler(commentButtonClick);
        this.commentedForm.button2ClickEvent += new control_Reply.Button2ClickHandler(replyButtonClick);

        //示例
        //this.setPicturePath("~/images/Logo.png");
        //this.Name = "可口可乐";
        //this.MaxBidPrice = "1000$";
        //this.MyBidPrice = "999$";
        //this.FinishTime = "4天前";
        //this.Result = "被我拍到";

        //this.commentForm.setState(control_Reply.ReplyState.afterCommentBeforReplied);
        //this.commentForm.setScore(4);
        //this.commentForm.Comment = "运送的有些慢";
        //this.commentForm.Reply = "";

        //this.commentedForm.setState(control_Reply.ReplyState.afterCommentedBeforeReply);
        //this.commentedForm.setScore(4);
        //this.commentedForm.Comment = "态度不好";
    }

    #region 字段
    //设置商品图片
    public void setPicturePath(String path)
    {
        imageButton.ImageUrl = path;// "~/images/Logo.png";
    }
    //设置商品id
    public int itemId;


    //设置商品名称
    public string Name
    {
        get { return name.Text; }
        set { name.Text = value; }
    }
    //设置商品最高竞标价格
    public string MaxBidPrice
    {
        get { return bidPrice.Text; }
        set { bidPrice.Text = value; }
    }
    //设置我投标的价格
    public string MyBidPrice
    {
        get { return myBidingPrice.Text; }
        set { myBidingPrice.Text = value; }
    }
    //竞拍结束时间
    public string FinishTime
    {
        get { return finishTime.Text; }
        set { finishTime.Text = value; }
    }
    //竞拍结果
    public string Result
    {
        get { return result.Text; }
        set { result.Text = value; }
    }
    public string Link
    {
        set
        {
            imageButton.PostBackUrl = value;
        }
    }
    #endregion

    #region 方法
    /// <summary>
    /// 设置当前登录用户对对方评论的状态
    /// </summary>
    /// <param name="state">用户对对方评论的状态</param>
    public void setCommentState(CommentState state)
    {
        switch(state)
        {
            case CommentState.noComment:
                {
                    this.commentForm.setState(control_Reply.ReplyState.noComment);
                    break;
                }
            case CommentState.beforeComment:
                {
                    this.commentForm.setState(control_Reply.ReplyState.beforeComment);
                    break;
                }
            case CommentState.afterCommentBeforReplied:
                {
                    this.commentForm.setState(control_Reply.ReplyState.afterCommentBeforReplied);
                    break;
                }
            case CommentState.afterReplied:
                {
                    this.commentForm.setState(control_Reply.ReplyState.afterReplied);
                    break;
                }
        }
        
    }
    /// <summary>
    /// 设置对方对当前登录用户评论的状态
    /// </summary>
    /// <param name="state">对方对当前登录用户评论的状态</param>
    public void setCommentedState(CommentedState state)
    {
        switch (state)
        {
            case CommentedState.beforeCommented:
                {
                    this.commentedForm.setState(control_Reply.ReplyState.beforeCommented);
                    break;
                }
            case CommentedState.afterCommentedBeforeReply:
                {
                    this.commentedForm.setState(control_Reply.ReplyState.afterCommentedBeforeReply);
                    break;
                }
            case CommentedState.afterReply:
                {
                    this.commentedForm.setState(control_Reply.ReplyState.afterReply);
                    break;
                }
        }

    }

    /// <summary>
    /// 设置当前登录用户对对方的打分
    /// </summary>
    /// <param name="starNumber">显示的星星的数目</param>
    /// <param name="score">当前登录用户对对方的打分</param>
    public void setCommentFormScore(int score)
    {
        this.commentForm.setScore(score);
    }
    /// <summary>
    /// 设置对方对当前登录用户的打分
    /// </summary>
    /// </summary>
    /// <param name="starNumber">显示的星星的数目</param>
    /// <param name="score">对方对当前登录用户的打分</param>
    public void setCommentedFormScore(int score)
    {
        this.commentedForm.setScore(score);
    }

    public int getCommentFormScore()
    {
        return commentForm.getScore();
    }
    public int getCommentedFormScore()
    {
        return commentedForm.getScore();
    }
    public string getComment()
    {
        return this.commentForm.Comment;
    }
    public string getReply()
    {
        return this.commentedForm.Reply;
    }
    /// <summary>
    /// 设置对对方的评论
    /// </summary>
    /// <param name="s">评论的内容</param>
    public void setCommentFormCommentText(string s)
    {
        this.commentForm.Comment = s;
    }
    /// <summary>
    /// 设置对方的评论
    /// </summary>
    /// <param name="s">评论的内容</param>
    public void setCommentedCommentText(string s)
    {
        this.commentedForm.Comment = s;
    }
    
    /// <summary>
    /// 设置对方对我的评论的回复
    /// </summary>
    /// <param name="s">回复的内容</param>
    public void setCommentFormReplyText(string s)
    {
        this.commentForm.Reply = s;
    }
    /// <summary>
    /// 设置我对对方的评论的回复
    /// </summary>
    /// <param name="s">回复的内容</param>
    public void setCommentedFormReplyText(string s)
    {
        this.commentedForm.Reply = s;
    }
    #endregion

    #region 事件处理
    // ImageButtonClick事件处理函数类型
    public delegate void ImageButtonClickHandler(object sender, EventArgs e);
    // ImageButtonClick事件
    public event ImageButtonClickHandler imageButtonClick;
    protected void imageButton_Click(object sender, ImageClickEventArgs e)
    {
        imageButtonClick(this, e);
    }

    public delegate void commentButtonClickHandler(object sender, EventArgs e);
    public event commentButtonClickHandler commentButtonClickEvent;
    //点击评论按钮事件处理
    public void commentButtonClick(object sender, EventArgs e)
    {
        //commentButtonClickEvent(this, e);
        //int score = this.commentForm.getScore();
        //String s = this.commentForm.Comment;
        ////数据库操作
        //刷新页面
    }

    public delegate void replyButtonClickHandler(object sender, EventArgs e);
    public event replyButtonClickHandler replyButtonClickEvent;
    //点击回复按钮事件处理
    public void replyButtonClick(object sender, EventArgs e)
    {
        String s = this.commentedForm.Reply;
        //数据库操作
        //刷新页面
    }
    #endregion
}